package com.lwy.qiuchao.integration.service.impl;


import org.springframework.stereotype.Service;


import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.lwy.qiuchao.integration.dao.IntegrationDao;
import com.lwy.qiuchao.integration.entity.IntegrationEntity;
import com.lwy.qiuchao.integration.service.IntegrationService;
import org.springframework.transaction.annotation.Transactional;


@Service("integrationService")
public class IntegrationServiceImpl extends ServiceImpl<IntegrationDao, IntegrationEntity> implements IntegrationService {

    @Override
    public void updateValueAdd(Long memberId, Integer inteValue){
        baseMapper.updateValueAdd(memberId,inteValue);
    }

    @Override
    public Integer getInteBymid(Map<String, Object> params) {
        String memberIdStr = (String) params.get("memberId");
        Long memberId = new Long(memberIdStr);
        IntegrationEntity entity = getOne(new QueryWrapper<IntegrationEntity>().eq("member_id", memberId));
        if(entity!=null){
            return entity.getTotalValue();
        }else{
            return 0;
        }
    }

    @Transactional
    @Override
    public void useIntevalue(Map<String, Object> params) {
        String memberIdStr = (String) params.get("memberId");
        Long memberId = new Long(memberIdStr);
        String totalValueStr = (String) params.get("totalValue");
        Integer totalValue = new Integer(totalValueStr);
        baseMapper.updateValueReduce(memberId,totalValue);
    }

}